package com.server.pinggu.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSONObject;
import com.server.common.utils.StringUtils;
import com.server.pinggu.upload.SenFormsExcel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@NoArgsConstructor
public class InitStockDataHandle extends AnalysisEventListener<SenFormsExcel> {


    private List<SenFormsExcel> excelModelList = new ArrayList<>();

    @Override
    public void invoke(SenFormsExcel data, AnalysisContext context) {
        String s = JSONObject.toJSONString(data);
        if (data == null ||StringUtils.isEmpty(s)|| s.equals("{}")){
            return;
        }
        log.info("解析了一条数据：{}", s);
        excelModelList.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //解析完excel后自动执行此方法
        log.info("开始处理数据");
    }


    public List<SenFormsExcel> getValue(){
        return excelModelList;
    }
}
